Show language: C# VB.NET Both

Assigning Location & Content Categories

This example demonstrates how to assign new documents added during import to a specific content category (testcon) and existing documents to be added when 'Auto Assign' is clicked from the Index Manager window. It is intended to provide you with a general guide for creating your own custom assembly for the Central Event System.

Please see the Central Event System overview.

C#
using Keyoti.SearchEngine;
using Keyoti.SearchEngine.Events;

namespace Keyoti.SearchEngine
{
	public class ExternalEventHandler 
	{
    
		private IEventDispatcher dispatcher;
    
		private Configuration conf;
    
		public ExternalEventHandler(IEventDispatcher dispatcher, Configuration conf) 
		{
			Keyoti.SearchEngine.DataAccess.Log.WriteLogEntry("CustomAssembly", "SUCCESS", conf);
			dispatcher.Action += new ActionEventHandler(dispatcher_Action);
			this.dispatcher = dispatcher;
			this.conf = conf;
		}
    
		public void DetachHandlers() 
		{
			dispatcher.Action -= new ActionEventHandler(dispatcher_Action);

		}
    
		public void dispatcher_Action(object sender, Keyoti.SearchEngine.Events.ActionEventArgs e) 
		{
			// here we pay attention to the auto assign event, and add every document to "testcon"
			if ((e.ActionData.Name == ActionName.AutoAssignContent)) 
			{
				Keyoti.SearchEngine.DataAccess.DocumentRecord rec;
				Keyoti.SearchEngine.DataAccess.XmlDataAccess da;
				rec = ((Keyoti.SearchEngine.DataAccess.DocumentRecord)(e.ActionData.Data));
				da = ((Keyoti.SearchEngine.DataAccess.XmlDataAccess)(sender));
				rec.ContentCategories.Add(da.GetContentCategoryRecord("testcon"));
			}
		}
	}
}
VB.NET
Imports Keyoti.SearchEngine
Imports Keyoti.SearchEngine.Events

 

Public Class ExternalEventHandler

    Dim dispatcher As IEventDispatcher
    Dim conf As Configuration

    Public Sub New(ByVal dispatcher As IEventDispatcher, ByVal conf As Configuration)

        Keyoti.SearchEngine.DataAccess.Log.WriteLogEntry("CustomAssembly", "SUCCESS", conf)
        AddHandler dispatcher.Action, New ActionEventHandler(AddressOf dispatcher_Action)

 

        Me.dispatcher = dispatcher
        Me.conf = conf
    End Sub

    Public Sub DetachHandlers()

        RemoveHandler dispatcher.Action, New ActionEventHandler(AddressOf dispatcher_Action)
    End Sub

    Public Sub dispatcher_Action(ByVal sender As Object, ByVal e As Keyoti.SearchEngine.Events.ActionEventArgs)

        'here we pay attention to the auto assign event, and add every document to "testcon"

        If e.ActionData.Name = ActionName.AutoAssignContent Then

            Dim rec As Keyoti.SearchEngine.DataAccess.DocumentRecord
            Dim da As Keyoti.SearchEngine.DataAccess.XmlDataAccess
            rec = CType(e.ActionData.Data, Keyoti.SearchEngine.DataAccess.DocumentRecord)
            da = CType(sender, Keyoti.SearchEngine.DataAccess.XmlDataAccess)
            'now we have the document being assigned, lets give it a preset category
            'for this to work a category called "testcon" must already exist
            rec.ContentCategories.Add(da.GetContentCategoryRecord("testcon"))

        End If
    End Sub

End Class